class SeanMeadowsTests extends GroovyTestCase {

    // Tests that would normally go into a file called UserTests.groovy

    def testUser = new User ()


    //try to save with null username; should fail
    void testSaveNullUsername() {

        testUser.userName = null
        testUser.password = "testpw"
        testUser.email = "sean@sbm.gotdns.com"
        shouldFail( testUser.save() )
    }

    //try to save with null password; should fail
    void testSaveNullPassword() {

        testUser.userName = "testUser000"
        testUser.password = null
        testUser.email = "sean@sbm.gotdns.com"
        shouldFail( testUser.save() )
    }

    //try to save with null email; should fail
    void testSaveNullEmail() {

        testUser.userName = "testUser000"
        testUser.password = "testPW"
        testUser.email = null
        shouldFail( testUser.save() )

    }

    //test validation of an invalid email; should fail
    void testInvalidEmail() {

        testUser.userName = "testUser000"
        testUser.password = "testPW"
        testUser.email = "invalidEmailaddress"

        assert testUser.validate() == false

        def fieldError = testUser.errors.getFieldError('email')
        def validationError = fieldError.codes.find {
              it == 'email.invalid'
         }
        assertNotNull(validationError)

    }

}
